home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
tvtoys04.zip
/
RESTEST.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-12-18
|
17KB
|
496 lines
(***************************************************************************
ResTest program
Official playground, odd bits and pieces, resources, config files etc
PJB October 8, 1993, Internet mail to d91-pbr@nada.kth.se
Copyright 1993, All Rights Reserved
Free source, use at your own risk.
If modified, please state so if you pass this around.
Demonstrates video config files, resource fonts and video tests
configurability. This program doesn't look for VESA and V7 without
being told to do so, it saves the desktop video state and it gives
transparent user access to resource fonts. There is also a self
modifying menu.
StoreCfg is currently used before ResDemoApp.Done so that no config
file is saved if the program aborts during initialization. This
was intended to prevent unnecessary elimination of video checks,
whether that is any good I don't know.
Another approach is to save a config file before testing that says
no testing should be done, and another after the testing with full
testing enabled. This doesn't leave anything to the user, but the
program might crash the first time, if the video BIOS is picky.
if not ConfigOK then { No config file }
begin
StoreCfg; { VideoTypesToCheck is [] }
VideoTypesToCheck:=[vtVesa,vtVideo7];
end;
inherited Init;
if not ConfigOK then { No config file }
StoreCfg; { VideoTypesToCheck is [vtVesa,vtVideo7] }
Be careful about using TV's message box in StoreCfg, though, there
might not be any application:
if (S.Status<>stOK) and (Application<>Nil) then
MessageBox(...)
***************************************************************************)
program ResTest;
{$I toyCfg}
{$B-,X+}
{$IFNDEF ResFonts}
Psst! Define ResFonts in TOYCFG.PAS, or this demo is gets boring!
{$ENDIF}
uses
App, Dialogs, Drivers, Menus, MsgBox, Objects, Views,
toyPrefs, {$I hcFile}
ColorBox, ColorSel, (* Color selection dialog *)
TVPal, Pal, (* Palette changing dialog *)
FontDlg, FontFiles, HelpFile, ModeDlg, StrmRec, toyApp, toyUtils,
TVVideo, TVUtils, Vesa, Video;
type
TResDemoApp =
object (TToyApp)
ResFile : TResourceFile;
LinesMenu : PMenu;
constructor Init;
procedure InitMenubar; virtual;
procedure CalcLinesMenu;
procedure CreateResourceFile;
procedure HandleEvent(var Event:TEvent); virtual;
procedure StoreCfg;
procedure VideoTestsDialog(VT:SpecialVideoTypes);
end;
(*******************************************************************
Demo commands
*******************************************************************)
const
toyStart = 100;
cm8p = toyStart+0;
cm14p = toyStart+1;
cm16p = toyStart+2;
cmVideoMode = toyStart+3;
cmVideoInfo = toyStart+4;
cmSelectFont = toyStart+5;
cmVideoTests = toyStart+6;
cm12p = toyStart+7;
cmColor = toyStart+8;
cmPalette = toyStart+9;
const
CfgName = 'RESTEST.CFG';
ResName = 'RESTEST.REZ';
(***************************************************************************
Things that belong in a unit
***************************************************************************)
(*******************************************************************
Restore a video state from stream
*******************************************************************)
procedure LoadVideoState(var S:TStream);
var
W : Word;
TVVideoState : VideoState;
begin
LoadVideoModes(S);
S.Read(TVVideoState, SizeOf(TVVideoState));
S.Read(LastFontNameLoaded, SizeOf(LastFontNameLoaded));
PToyApp(Application)^.LoadPalette(S); (* requires Application <> Nil *)
VideoPalette.Load(S);
S.Read(LastFontTypeUsed, SizeOf(LastFontTypeUsed));
if S.Status=stOK then
TVVideoState.Restore;
end;
(*******************************************************************
Store current video state on a stream
*******************************************************************)
procedure StoreVideoState(var S:TStream);
var
TVVideoState : VideoState;
begin
StoreVideoModes(S);
TVVideoState.Save;
S.Write(TVVideoState, SizeOf(TVVideoState));
S.Write(LastFontNameLoaded, SizeOf(LastFontNameLoaded));
PToyApp(Application)^.StorePalette(S);
VideoPalette.Store(S);
S.Write(LastFontTypeUsed, SizeOf(LastFontTypeUsed));
end;
(***************************************************************************
The application
***************************************************************************)
(*******************************************************************
Init app, load a config file with video info if there (this is
what messes it up), create resource file if necessary
This code includes TToyApp's Init, so we call TApplication.Init
directly.
Ideally we don't call TApplication.Init at all, but rather init
the app first (without calling InitVideo) and then decide what
kind of video initalizing we want...
*******************************************************************)
constructor TResDemoApp.Init;
var
S : TDosStream;
ConfigOK : Boolean;
InitState : VideoState;
begin
Application:=@Self; (* Cheat, cheat, cheat... (for LoadVideoState) *)
RegisterObjects;
RegisterFontFile;
RegisterHelpFile;
(*******************************************************************
Open and read config file if there is one
*******************************************************************)
{ Do we have a config file? }
S.Init(ExeDir+CfgName, stOpenRead);
{ This zeros VideoTypesToCheck if no cfg file, so checks only EVGA }
S.Read(VideoTypesToCheck, SizeOf(VideoTypesToCheck));
CheckVideoType; (* Determine video type *)
InitState.Save; (* Use temporary variable... *)
VideoPalette.Init; (* Initialize palette *)
LoadVideoState(S); (* Load previously saved video state *)
S.Done;
ConfigOK:=S.Status=stOK;
(*******************************************************************
Init app, TToyApp replacement code
*******************************************************************)
if ConfigOK then
begin
PreventModeSwitch; (* We loaded a new video mode *)
VideoPalette.SetRGB(VideoPalette.RGB);
end;
TApplication.Init; (* We don't want to call TToyApp.Init *)
DosVideoState:=InitState; (* Save startup video mode *)
(* Get ScreenMode (if there is no cfg file) *)
ScreenMode:=GetSpecialVideoMode;
(*******************************************************************
Introductory text
*******************************************************************)
HelpFileName:='HELPTEST.HLP';
ShowHelp(hcRezIntro);
(*******************************************************************
Is there a resource file? No? Create it!
*******************************************************************)
S.Init(ExeDir+ResName, stOpenRead);
S.Done;
if S.Status<>stOK then
CreateResourceFile; { No, create it }
(*******************************************************************
Open the resource file
*******************************************************************)
ResFile.Init(New(PBufStream, Init(ExeDir+ResName, stOpenRead, 1024)));
if ResFile.Stream^.Status<>stOK then (* OOPS! *)
begin
MessageBox(^C'Resource file not readable', Nil, mfError+mfOKButton);
Done;
Halt;
end;
(*******************************************************************
Reload last font, might need resource file
*******************************************